/*************************************************************************
	> File Name: test13.c
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023年08月23日 星期三 21时53分26秒
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

int main() {
    pid_t id = fork();
    if (id < 0) {
        perror("fork");
        exit(-1);
    } else if (id == 0) {
        printf("Child Process running, pid:%d\n", getpid());
        sleep(1);
        char *const _argv[] = {
            "ls",
            "-l",
            "-a",
            "-i",
            NULL
        };
        printf("The end code of the current process\n");
    } else {
        printf("Father Process running, pid:%d\n", getpid());
        int status = 0;
        pid_t res = waitpid(-1, &status, 0);
        if (res > 0) printf("Wait success, exit code:%d\n", WEXITSTATUS(status));
    }
    return 0;
}
